import { readFile, writeFile } from "fs"

function orbitProcessing(path) {
    // Read from input file
    readFile(`./scripts/data/${path}.txt`, 'utf8', (err, txtData) => {
        if (err) {
            console.error('Error reading file:', err);
            return;
        }

        // Process the data
        const lines = txtData.split('\n').filter(line => line.trim() !== '');
        // const dataLines = lines.slice(4); // Skip the header lines

        const mainPositionList = lines.map(line => {
            // const parts = line.split(/\s+/).filter(part => part !== '');
            // const dateTime = parts.slice(0, 5).join(' ');
            // const lat = parts[5];
            // const lon = parts[6];
            // const alt = parts[7];
            // const latRate = parts[8];
            // const lonRate = parts[9];
            // const altRate = parts[10];

            return {
                dataTime: line
            };
        });

        // Create the output content
        const outputContent = `const ${path} = [
${mainPositionList.map(item => `  {
    dataTime: "${item.dataTime}",
  },`).join('\n')}
];`;

        // Write to output file
        writeFile(`./scripts/data/${path}.js`, outputContent, (err) => {
            if (err) {
                console.error('Error writing file:', err);
            } else {
                console.log('Successfully wrote to output.js');
            }
        });
    });
}


orbitProcessing('BlueSat_J2000_Position_Velocity');
orbitProcessing('RedSat_J2000_Position_Velocity');